<!--
 * @Author: WuFeng <763467339@qq.com>
 * @Date: 2022-03-22 12:12:49
 * @LastEditTime: 2023-03-15 18:28:18
 * @LastEditors: WuFeng <763467339@qq.com>
 * @Description:
 * @FilePath: \vue3-element-plus-web\src\views\Layouts\Admin\index.vue
 * Copyright 版权声明
-->
<template>
  <div class="app-wrapper" :class="classObj">
    <el-scrollbar>
      <div v-if="device==='mobile'&&sidebar.opened" class="drawer-bg" @click="handleClickOutside"></div>
      <sidebar class="sidebar-container"></sidebar>
      <div class="main-container">
        <!-- 当前系统内路由 - 展示标签页，反之亦然 -->
        <navbar></navbar>
        <template v-if="iframeHref === ''">
          <tags-view></tags-view>
        </template>
        <app-main></app-main>
      </div>
      <!-- 全局抽屉组件 -->
      <global-drawer v-if="drawerVisible"></global-drawer>
    </el-scrollbar>
    <!-- 切换角色组件 -->
    <RoleSwitchDialog></RoleSwitchDialog>
  </div>
</template>

<script>
import { mapGetters } from 'vuex'
import {
  Navbar,
  Sidebar,
  AppMain,
  TagsView
} from './components'
// 切换角色组件
import RoleSwitchDialog from './components/RoleSwitch/Dialog.vue'
import ResizeMixin from './mixin/ResizeHandler'

export default {
  name: 'layout',
  components: {
    Navbar,
    Sidebar,
    AppMain,
    TagsView,
    RoleSwitchDialog
  },
  mixins: [ResizeMixin],
  computed: {
    sidebar() {
      return this.$store.state.app.sidebar
    },
    device() {
      return this.$store.state.app.device
    },
    classObj() {
      return {
        hideSidebar: !this.sidebar.opened, // 折叠 左侧菜单
        openSidebar: this.sidebar.opened, // 展开 左侧菜单
        withoutAnimation: this.sidebar.withoutAnimation,
        mobile: this.device === 'mobile', // 移动端展示
        mixedMenuLayout: this.layoutType === 'mixedMenuLayout', // 混合 菜单布局（左侧 + 顶部）
        leftMenuLayout: this.layoutType === 'leftMenuLayout', // 左侧 菜单布局
        topMenuLayout: this.layoutType === 'topMenuLayout', // 顶部 菜单布局
        defaultTheme: this.sysTheme === 'defaultTheme', // 系统主题 - 默认主题
        nightTheme: this.sysTheme === 'nightTheme' // 系统主题 - 夜间模式
      }
    },
    ...mapGetters([
      'drawerVisible',
      'layoutType',
      'sysTheme',
      'iframeHref'
    ])
  },
  methods: {
    handleClickOutside() {
      this.$store.dispatch('CloseSideBar', { withoutAnimation: false })
    }
  }
}
</script>

<style rel="stylesheet/scss" lang="scss" scoped>
  @import "src/styles/mixin.scss";
  .app-wrapper {
    @include clearfix;
    position: relative;
    height: 100%;
    width: 100%;
    &.mobile.openSidebar{
      position: fixed;
      top: 0;
    }
  }
  .drawer-bg {
    background: #000;
    opacity: 0.3;
    width: 100%;
    top: 0;
    height: 100%;
    position: absolute;
    z-index: 999;
  }
</style>
